﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.nodes.mssql;
using SharpSqlAnalyzer.nodes.oracle;

namespace SharpSqlAnalyzer.stmt
{
	// Token: 0x020000C5 RID: 197
	public class TUpdateSqlStatement : TCustomSqlStatement
	{
		// Token: 0x1700014B RID: 331
		// (get) Token: 0x06000716 RID: 1814 RVA: 0x002FFE3C File Offset: 0x002FE03C
		// (set) Token: 0x06000717 RID: 1815 RVA: 0x002FFE44 File Offset: 0x002FE044
		public virtual TErrorLoggingClause ErrorLoggingClause
		{
			get
			{
				return this._errorLoggingClause;
			}
			set
			{
				this._errorLoggingClause = value;
			}
		}

		// Token: 0x1700014C RID: 332
		// (get) Token: 0x06000718 RID: 1816 RVA: 0x002FFE4D File Offset: 0x002FE04D
		// (set) Token: 0x06000719 RID: 1817 RVA: 0x002FFE55 File Offset: 0x002FE055
		public virtual TOptionClause OptionClause
		{
			get
			{
				return this._optionClause;
			}
			set
			{
				this._optionClause = value;
			}
		}

		// Token: 0x1700014D RID: 333
		// (get) Token: 0x0600071B RID: 1819 RVA: 0x002FFE67 File Offset: 0x002FE067
		// (set) Token: 0x0600071A RID: 1818 RVA: 0x002FFE5E File Offset: 0x002FE05E
		public virtual TSourceToken UpdateToken
		{
			get
			{
				return this._updateToken;
			}
			set
			{
				this._updateToken = value;
			}
		}

		// Token: 0x1700014E RID: 334
		// (get) Token: 0x0600071C RID: 1820 RVA: 0x002FFE6F File Offset: 0x002FE06F
		// (set) Token: 0x0600071D RID: 1821 RVA: 0x002FFE8A File Offset: 0x002FE08A
		public virtual TJoinList ReferenceJoins
		{
			get
			{
				if (this._referenceJoins == null)
				{
					this._referenceJoins = new TJoinList();
				}
				return this._referenceJoins;
			}
			set
			{
				this._referenceJoins = value;
			}
		}

		// Token: 0x1700014F RID: 335
		// (get) Token: 0x0600071E RID: 1822 RVA: 0x002FFE93 File Offset: 0x002FE093
		// (set) Token: 0x0600071F RID: 1823 RVA: 0x002FFE9B File Offset: 0x002FE09B
		public virtual TLimitClause LimitClause
		{
			get
			{
				return this._limitClause;
			}
			set
			{
				this._limitClause = value;
			}
		}

		// Token: 0x17000150 RID: 336
		// (get) Token: 0x06000720 RID: 1824 RVA: 0x002FFEA4 File Offset: 0x002FE0A4
		// (set) Token: 0x06000721 RID: 1825 RVA: 0x002FFEAC File Offset: 0x002FE0AC
		public virtual TOrderBy OrderByClause
		{
			get
			{
				return this._orderByClause;
			}
			set
			{
				this._orderByClause = value;
			}
		}

		// Token: 0x06000722 RID: 1826 RVA: 0x002FFEB5 File Offset: 0x002FE0B5
		public TUpdateSqlStatement(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstupdate;
		}

		// Token: 0x06000723 RID: 1827 RVA: 0x002FFEC5 File Offset: 0x002FE0C5
		internal override void buildsql()
		{
		}

		// Token: 0x06000724 RID: 1828 RVA: 0x002FFEC7 File Offset: 0x002FE0C7
		internal override void clear()
		{
		}

		// Token: 0x06000725 RID: 1829 RVA: 0x002FFEC9 File Offset: 0x002FE0C9
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x06000726 RID: 1830 RVA: 0x002FFED0 File Offset: 0x002FE0D0
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x06000727 RID: 1831 RVA: 0x002FFED4 File Offset: 0x002FE0D4
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			TUpdateSqlNode tupdateSqlNode = (TUpdateSqlNode)this.rootNode;
			if (this.sourcetokenlist.size() == 0)
			{
				base.startToken = tupdateSqlNode.startToken;
				base.endToken = tupdateSqlNode.endToken;
			}
			base.doParseStatement(psql);
			this._updateToken = tupdateSqlNode.UpdateToken;
			base.scanOracleHint(this._updateToken);
			if (tupdateSqlNode.cteList != null)
			{
				this.CteList = tupdateSqlNode.cteList;
				this.CteList.doParse(this, ESqlClause.cte);
			}
			if (tupdateSqlNode.TopClause != null)
			{
				tupdateSqlNode.TopClause.doParse(this, ESqlClause.top);
				this.TopClause = tupdateSqlNode.TopClause;
			}
			if (tupdateSqlNode.TargetTable.FromtableType != ETableSource.join)
			{
				TTable ttable = this.analyzeFromTable(tupdateSqlNode.TargetTable, new bool?(true));
				ttable.EffectType = ETableEffectType.tetUpdate;
				this.TargetTable = ttable;
			}
			else
			{
				TJoin tjoin = this.analyzeJoin(tupdateSqlNode.TargetTable.JoinExpr, null, new bool?(true));
				tjoin.doParse(this, ESqlClause.join);
				this.TargetTable = tjoin.Table;
				this.joins.addJoin(tjoin);
			}
			if (tupdateSqlNode.OutputClause != null)
			{
				tupdateSqlNode.OutputClause.doParse(this, ESqlClause.output);
				this.OutputClause = tupdateSqlNode.OutputClause;
			}
			if (tupdateSqlNode.SourceTableList != null)
			{
				for (int i = 0; i < tupdateSqlNode.SourceTableList.size(); i++)
				{
					TFromTable fromTable = tupdateSqlNode.SourceTableList.getFromTable(i);
					TJoin tjoin2;
					if (fromTable.FromtableType != ETableSource.join)
					{
						tjoin2 = new TJoin();
						TTable ttable2 = this.analyzeFromTable(fromTable, new bool?(true));
						ttable2.EffectType = ETableEffectType.tetSelect;
						tjoin2.Table = ttable2;
					}
					else
					{
						tjoin2 = this.analyzeJoin(fromTable.JoinExpr, null, new bool?(true));
						tjoin2.doParse(this, ESqlClause.join);
					}
					this.joins.addJoin(tjoin2);
				}
			}
			this.ResultColumnList = tupdateSqlNode.ResultColumnList;
			this.ResultColumnList.doParse(this, ESqlClause.set);
			if (tupdateSqlNode.ReferenceTableList != null)
			{
				for (int j = 0; j < tupdateSqlNode.ReferenceTableList.size(); j++)
				{
					TFromTable fromTable2 = tupdateSqlNode.ReferenceTableList.getFromTable(j);
					TJoin tjoin3;
					if (fromTable2.FromtableType != ETableSource.join)
					{
						tjoin3 = new TJoin();
						TTable ttable3 = this.analyzeFromTable(fromTable2, new bool?(true));
						ttable3.EffectType = ETableEffectType.tetSelect;
						tjoin3.Table = ttable3;
					}
					else
					{
						tjoin3 = this.analyzeJoin(fromTable2.JoinExpr, null, new bool?(true));
						tjoin3.doParse(this, ESqlClause.join);
					}
					this.joins.addJoin(tjoin3);
				}
			}
			if (tupdateSqlNode.WhereCondition != null)
			{
				tupdateSqlNode.WhereCondition.doParse(this, ESqlClause.where);
				this.WhereClause = tupdateSqlNode.WhereCondition;
			}
			if (tupdateSqlNode.ReturningClause != null)
			{
				tupdateSqlNode.ReturningClause.doParse(this, ESqlClause.returning);
				this.ReturningClause = tupdateSqlNode.ReturningClause;
			}
			this._optionClause = tupdateSqlNode.OptionClause;
			this._errorLoggingClause = tupdateSqlNode.ErrorLoggingClause;
			int[] array = new int[this.tables.size()];
			for (int k = 0; k < this.tables.size(); k++)
			{
				TTable table = this.tables.getTable(k);
				if (table.AliasClause == null && table.BaseTable)
				{
					for (int l = 0; l < this.tables.size(); l++)
					{
						if (k != l)
						{
							TTable table2 = this.tables.getTable(l);
							if (table2.AliasClause != null && string.Compare(table2.AliasClause.ToString(), table.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0)
							{
								array[k] = 1;
								table.setLinkTable(true);
								table.setLinkTable(table2);
							}
						}
					}
				}
			}
			return 0;
		}

		// Token: 0x06000728 RID: 1832 RVA: 0x00300278 File Offset: 0x002FE478
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x06000729 RID: 1833 RVA: 0x00300288 File Offset: 0x002FE488
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.CteList != null)
			{
				this.CteList.acceptChildren(v);
			}
			if (this.TopClause != null)
			{
				this.TopClause.acceptChildren(v);
			}
			this.TargetTable.acceptChildren(v);
			if (this.OutputClause != null)
			{
				this.OutputClause.acceptChildren(v);
			}
			if (this.joins.size() > 0)
			{
				this.joins.acceptChildren(v);
			}
			this.ResultColumnList.acceptChildren(v);
			if (this.WhereClause != null)
			{
				this.WhereClause.acceptChildren(v);
			}
			if (this.OrderByClause != null)
			{
				this.OrderByClause.acceptChildren(v);
			}
			if (this.LimitClause != null)
			{
				this.LimitClause.acceptChildren(v);
			}
			if (this.ReturningClause != null)
			{
				this.ReturningClause.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x040011D2 RID: 4562
		private TErrorLoggingClause _errorLoggingClause;

		// Token: 0x040011D3 RID: 4563
		private TOptionClause _optionClause;

		// Token: 0x040011D4 RID: 4564
		private TSourceToken _updateToken;

		// Token: 0x040011D5 RID: 4565
		private TJoinList _referenceJoins;

		// Token: 0x040011D6 RID: 4566
		private TOrderBy _orderByClause;

		// Token: 0x040011D7 RID: 4567
		private TLimitClause _limitClause;
	}
}
